package com.yoda.mall.admin.controller;

import com.yoda.common.Status;
import com.yoda.mall.admin.service.SkuStockService;
import com.yoda.mall.api.SkuStockApi;
import com.yoda.mall.model.entity.pms.SkuStock;
import com.yoda.mall.model.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shawn
 * @date 2022年 12月 18日 20:31
 */
@RestController
@RequestMapping("sku")
public class SkuStockController {

    @Resource
    private SkuStockService skuStockService;


    @GetMapping("/{pid}")
    public R getSku(@PathVariable Long pid,String keyword){
        List<SkuStock> skuStocks = skuStockService.getSkuByProductId(pid,keyword);
        return R.success(skuStocks);
    }

    @PostMapping("/update/{pid}")
    public R updateProductSkuStock(@PathVariable Long pid ,@RequestBody List<SkuStock> skuStockList){
        if (skuStockList.size()==0){
            return R.error(Status.FORBIDDEN.getMessage(),Status.FORBIDDEN.getCode());
        }
        Integer count = skuStockService.updateProductSkuStock(pid,skuStockList);
        return R.success(count);
    }
}
